package it.polimi.traveldream.ejb.bean;



import it.polimi.authentication.ejb.usermanagement.AddNewCity;
import it.polimi.authentication.ejb.usermanagement.AddNewHotel;
import it.polimi.authentication.ejb.usermanagement.AddNewMezzo;
import it.polimi.authentication.ejb.usermanagement.Hotel;
import it.polimi.authentication.ejb.usermanagement.MezzoDiTrasporto;
import it.polimi.authentication.ejb.usermanagement.Pacchetto;
import it.polimi.authentication.ejb.usermanagement.Citta;
import it.polimi.authentication.ejb.usermanagement.PacchettoCitta;
import it.polimi.authentication.ejb.usermanagement.PacchettoPredefinito;
import it.polimi.authentication.ejb.usermanagement.dto.CittaDTO;
import it.polimi.authentication.ejb.usermanagement.dto.HotelDTO;
import it.polimi.authentication.ejb.usermanagement.dto.MezzoDTO;
import it.polimi.authentication.ejb.usermanagement.dto.PacchettoPredefinitoDTO;
import it.polimi.authentication.ejb.usermanagement.dto.Pacchetto_cittaDTO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJBContext;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * Session Bean implementation class UserBean
 */
@Stateless
public class AggiungiNuovoMezzo implements AddNewMezzo{


	@PersistenceContext
    private EntityManager em;
	
	public AggiungiNuovoMezzo(){	
	}
	
	@Override
	public void add(MezzoDTO mezzo)
	{
		//crea nuovo mezzo
		MezzoDiTrasporto newM = new MezzoDiTrasporto (mezzo);
		System.out.println(newM.getOraarrivo());
		newM.setDisponibile(true);
		//inserisci 	
		em.persist(newM);
	}
	
	
	@Override 
	public void canc (ArrayList <String> MezziC)
	{
		for (int i=0; i< MezziC.size(); i++)
		{
			Query query = em.createQuery ("UPDATE MezzoDiTrasporto m SET m.Disponibile = 0 WHERE m.mezzo = '"+ MezziC.get(i)+"'");
			int updateCount = query.executeUpdate();
		}
	}
	
	
}


